#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
#include <queue>
#include <iostream>


inline bool Is7(int n) {
    int nBak = n;
    while (n > 0) {
        if (n % 10 == 7) {
            return true;
        }
        n /= 10;
    }
    return nBak % 7 == 0;
}

/**
 * 时间复杂度:
 * 输入：O(n)
 * 旋转：O(m)
 * 主循环：O(n * log(n+t))
 * 
 * 总体：O(n * log(n))
 * 
 * 空间复杂度：O(20*n)
 * 
 *
 * 敲7
 * @return
 */
int main() {
    int n, m, t;
    scanf("%d%d%d", &n, &m, &t);

    std::queue<std::string> names;
    for (int i = 0; i < n; i++) {
        std::string name;
        std::cin >> name;
        names.push(name);
    }

    for (int i = 0; i < m-1; i++) {
        names.push(names.front());
        names.pop();
    }

    while (names.size() > 1) {
        if (Is7(t)) {
            names.pop();
        }
        else {
            names.push(names.front());
            names.pop();
        }
        t++;
    }

    std::cout << names.front();

    return 0;
}
